//
//  FJRecordCell.swift
//  FruitJuice
//
//  Created by Rui on 2024/1/7.
//

import UIKit

class FJRecordCell: UITableViewCell {

    private let iconImageView       = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(22.5).end()
    private let nameLabel           = c_make_ex(UILabel.self)
        .color(.white).font(18.font_bold).line(2).end()
    private let timeLabel           = c_make_ex(UILabel.self)
        .color(.white).font(14.font_regular).end()
    private let delButton        = c_make_ex(UIButton.self)
        .image("FJ_Home_Record_del").end()
    private let shadowView        = c_make_ex(UIView.self).end()
    
    var delClosure: ((_ roomId: String) -> Void)?
    
    var model:InfoUtil.commentDta?{
        didSet{
            guard let md = model else {
                return
            }
//            iconImageView.loadImage(url: md.userImage)
//            nameLabel.text = md.userName
//            contentLabel.text = md.msg
//            timeLabel.text = md.createTime
//            if md.userId == USEINFOMODEL.id {
//                reportButton.isHidden = true
//            }else{
//                reportButton.isHidden = false
//            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews {
            iconImageView.subviews{
                shadowView
                nameLabel
                timeLabel
                delButton
            }
        }

        iconImageView.leading(15).trailing(15).top(0).height(200)
        delButton.trailing(0).top(0).size(40)
        timeLabel.leading(15).bottom(15)
        nameLabel.leading(15).width(190)
        nameLabel.Bottom == timeLabel.Top
        shadowView.leading(0).trailing(0).bottom(0).height(70)
        
        delButton.addTarget(self, action: #selector(deleteRoom), for: .touchUpInside)
    }
    
    @objc private func deleteRoom(){
        if let roomId = model?.id {
            delClosure?(roomId)
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        shadowView.fj.gradientColors(.bottomToTop([.black.alpha(0),.black.alpha(0.49)]))
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

class FJRecordTitleHeaderView: UITableViewHeaderFooterView {

    var titleLabel = c_make_ex(UILabel.self)
        .color(.black).font(21.font_bold).end()
    
    var titleStr = "" {
        didSet{
            titleLabel.text = titleStr
        }
    }
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        setSubviews()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }

    func setSubviews(){
        
        contentView.subviews{
            titleLabel
        }
        titleLabel.leading(15).centerVertically()
    }
}
